package cn.edu.zzuli.wechat.user.controller;

import cn.edu.zzuli.common.result.Result;
import cn.edu.zzuli.common.result.ResultInfo;
import cn.edu.zzuli.model.vo.wx.CompVo;
import cn.edu.zzuli.wechat.filter.NoAuth;
import cn.edu.zzuli.wechat.user.service.ComplaintService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class ComplaintController {

    @Autowired
    private ComplaintService complaintService;


    @ApiOperation("申诉/投诉")
    @PostMapping("complaint")
    public ResultInfo insert(@RequestBody(required = false)CompVo compVo, HttpSession session){
        System.out.println(compVo);
        Integer uid = (Integer) session.getAttribute("uid");
        Boolean res = complaintService.apply(compVo.getUrls(),compVo.getDescription(),uid,compVo.getType());
        return res == true ? Result.ok() : Result.fail();
    }

    @NoAuth
    @ApiOperation("申诉/投诉")
    @PostMapping("uploadFile")
    public ResultInfo complaint(MultipartFile file){
        String res = complaintService.upload(file);
        System.out.println(file.getOriginalFilename());
        return  Result.ok(res);
    }
}
